using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace CodRevit.Converters
{
    public class RoleToBackgroundConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string role = value as string;
            switch (role?.ToLower())
            {
                case "user":
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D0D2FB"));
                case "assistant":
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F5F5F5"));
                default:
                    return new SolidColorBrush(Colors.White);
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class RoleToAlignmentConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string role = value as string;
            return role?.ToLower() == "user" ? HorizontalAlignment.Right : HorizontalAlignment.Left;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    //���ݽ�ɫ����ת��Ϊ����
    public class RoleToNameConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string role)
            {
                return role.ToLower() == "user" ? "Lemon" : "Assistant";
            }
            return string.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    // ����ɫ����ת��Ϊͷ��ɼ���
    public class RoleToAvatarVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //.Collapsed��Ԫ���ǲ��ɼ��ģ����Ҳ�ռ�ò��ֿռ�;hidden��Ԫ���ǲ��ɼ��ģ�����ռ�ò��ֿռ䡣
            if (value is string role)
            {
                return role.ToLower() == "assistant" ? Visibility.Visible : Visibility.Collapsed;
            }
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    // ����ɫ����ת��Ϊͷ��ɼ���
    public class RoleToUserAvatarVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string role)
            {
                return role.ToLower() == "user" ? Visibility.Visible : Visibility.Collapsed;
            }
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}